<?php
/**
 * Created by PhpStorm.
 * User: 曹乐清
 * Date: 2017/3/21
 * Time: 9:56
 */

namespace Home\Controller;


use Think\Controller;

class ClientController extends CommonController
{


    //@todo 加载客户端列表
    public function index(){
        $this->display();
    }
    public function getAccessToken(){
        $url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxdea5bea284c15057&secret=159326a1e121edb999f199d076a785e5';
        $res=HttpCurl($url);
       return $res;
    }

    //获取用户列表
    public function get_client_list(){
        $open_id_count=D('client_user')->count();
        $open_id_list=D('client_user')->limit($_GET['offset'],$_GET['limit'])->select();
        if($_SESSION['expires_in']<time()){
            $access_token=$this->getAccessToken();
            if(!isset($access_token['errcode'])) {
                $_SESSION['access_token'] = $access_token['access_token'];
                $_SESSION['expires_in'] = time() + (int)$access_token['expires_in'];
                $this->get_client_list();
            }
        }else{
            $getOpenId=array_column($open_id_list,'openid');
            $user_list=array();
            foreach($getOpenId as $key=>$value){
                $user_list[$key]['openid']=$value;
                $user_list[$key]['lang']='zh-CN';
            }
            $get_user_info_url='https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token='.$_SESSION['access_token'];
            $result=HttpCurl($get_user_info_url,$user_list);
            var_dump($result);
        }

    }
}